import { Lv70NpcTalkData } from "../../data/Lv70NpcTalkData";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
type int = number;
//class Lv70NpcTalkMask
    
    export  class Lv70NpcTalkMask /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._masks = [];
            return;
        }

        public reInit(arg1: Lv70NpcTalkData, arg2: GTextFiled, arg3: Function): void
        {
            this._data = arg1;
            this._lineNum = arg2.numLines;
            this._text = arg2;
            this._onEnd = arg3;
            this._curIndex = 0;
            this.refleshAndStart();
            return;
        }

        public finishRightNow(): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._masks.length) 
            {
                loc2 = this._masks[loc1] as Object /* flash.display.Sprite */;
                loc2.x = 0;
                ++loc1;
            }
            this.endAndCallback();
            return;
        }

        public reWidth(arg1: number): void
        {
            var loc2=null;
            if (this._data == null) 
            {
                return;
            }
            if (this._isProcessing) 
            {
                this._reWidthed = true;
                this._isProcessing = false;
                this.endAndCallback();
            }
            var loc1=0;
            while (loc1 < this._masks.length) 
            {
                loc2 = this._masks[loc1] as Object /* flash.display.Sprite */;
                loc2.graphics.clear();
                loc2.graphics.beginFill(16777215, 0);
                loc2.graphics.drawRect(0, 0, arg1, this._data.talkFontSize + this._data.talkFontLeading);
                loc2.graphics.endFill();
                loc2.x = 0;
                ++loc1;
            }
            return;
        }

        public stop(): void
        {
            this._isProcessing = false;
            this.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEveryFrame);
            return;
        }

        /* internal  */refleshAndStart(): void
        {
            this.initMasks();
            this._isProcessing = true;
            this.addEventListener(flash.events.Event.ENTER_FRAME, this.onEveryFrame);
            return;
        }

        /* internal  */onEveryFrame(arg1: Object /* flash.events.Event */): void
        {
            if (this._reWidthed) 
            {
                this._reWidthed = false;
                return;
            }
            var loc1=this._masks[this._curIndex] as Object /* flash.display.Sprite */;
            var loc2=this._text.getLineMetrics(this._curIndex);
            loc1.x = loc1.x + this._data.speed;
            if (loc1.x > loc2.width + 8 - this._data.rowWidth) 
            {
                loc1.x = loc2.width + 8 - this._data.rowWidth;
                var loc3;
                var loc4=((loc3 = this)._curIndex + 1);
                loc3._curIndex = loc4;
                if (this._curIndex >= this._lineNum) 
                {
                    this.endAndCallback();
                }
            }
            return;
        }

        /* internal  */endAndCallback(): void
        {
            this._isProcessing = false;
            this.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEveryFrame);
            if (this._onEnd != null) 
            {
                this._onEnd.apply();
                this._onEnd = null;
            }
            return;
        }

        /* internal  */initMasks(): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._lineNum + 1) 
            {
                if (loc1 < this._masks.length) 
                {
                    loc2 = this._masks[loc1] as Object /* flash.display.Sprite */;
                    loc2.graphics.clear();
                    loc2.graphics.beginFill(16777215, 0);
                    loc2.graphics.drawRect(0, 0, this._data.rowWidth, this._data.talkFontSize + this._data.talkFontLeading);
                    loc2.graphics.endFill();
                    loc2.x = -this._data.rowWidth;
                    loc2.y = loc1 * loc2.height;
                }
                else 
                {
                    loc2 = new Object /* flash.display.Sprite */();
                    loc2.graphics.beginFill(16777215, 0);
                    loc2.graphics.drawRect(0, 0, this._data.rowWidth, this._data.talkFontSize + this._data.talkFontLeading);
                    loc2.graphics.endFill();
                    loc2.x = -this._data.rowWidth;
                    loc2.y = loc1 * loc2.height;
                    this._masks.push(loc2);
                    this.addChild(loc2);
                }
                ++loc1;
            }
            return;
        }

        /* internal  */getPixesNum(): int
        {
            var loc1=0;
            var loc2=0;
            while (loc2 < this._data.talk.length) 
            {
                if (this._data.talk.charCodeAt(loc2) < 255) 
                {
                    loc1 = loc1 + this._data.talkFontSize / 2;
                }
                else 
                {
                    loc1 = loc1 + this._data.talkFontSize;
                }
                ++loc2;
            }
            return loc1;
        }

        public getLineNum(): int
        {
            return this._lineNum;
        }

        /* internal */ /* var */_data: Lv70NpcTalkData;

        /* internal */ /* var */_masks: Array<any>;

        /* internal */ /* var */_curIndex: int;

        /* internal */ /* var */_onEnd: Function;

        /* internal */ /* var */_lineNum: int;

        /* internal */ /* var */_text: GTextFiled;

        /* internal */ /* var */_isProcessing: Boolean=false;

        /* internal */ /* var */_nextWidth: number=600;

        /* internal */ /* var */_shouldReWidth: Boolean=false;

        /* internal */ /* var */_reWidthed: Boolean=false;
    }
